<template>
  <div>
    <!-- 渲染角色列表 -->
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="obj in roleList" :key="obj.id" :label="obj.id">
        {{ obj.name }}
      </el-checkbox>
    </el-checkbox-group>

    <el-row class="footer" type="flex" justify="center">
      <el-col :span="6">
        <el-button type="primary" size="small" @click="enterFn">确定</el-button>
        <el-button size="small" @click="cancelFn">取消</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'AssignRole',
  props: {
    // 父传子->接收所有角色列表
    roleList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      // 复习: 复选框v-model变量类名是数组: 收集值
      // 复选框v-model变量类型非数组: 收集选中状态
      roleIds: [] // 收集用户选择角色ID
    }
  },
  methods: {
    // 确定->分配角色
    enterFn() {
      this.$emit('saveRoleIdsEV', this.roleIds)
      // 需要子组件清空变量, 才需要拷贝出去
    },
    // 取消->关闭弹窗
    cancelFn() {
      this.$emit('input', false)
    }
  }
}
</script>

<style lang="scss" scoped>
.footer {
  margin-top: 30px;
}
</style>
